package com.atguigu.jxc.controller;


import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.service.GoodsService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/goods")
public class GoodsController {


    @Autowired
    private GoodsService goodsService;


    @RequestMapping("/listInventory")
    @RequiresPermissions(value = "当前库存查询")
    public Map<String,Object> listInventory(Integer page, Integer rows, String codeOrName, Integer goodsTypeId){
        return goodsService.listInventory(page, rows, codeOrName, goodsTypeId);
    }

    @RequestMapping("/list")
    @RequiresPermissions(value={"商品管理","进货入库","退货出库","销售出库","客户退货","商品报损","商品报溢"},logical= Logical.OR)
    public Map<String,Object> list(Integer page,Integer rows,String goodsName,Integer goodsTypeId){
        return goodsService.list(page,rows,goodsName,goodsTypeId);
    }

    @RequestMapping("/save")
    @RequiresPermissions(value = "商品管理")
    @ResponseBody
    public ServiceVO save(Goods goods){
        return goodsService.save(goods);
    }

    @RequestMapping("/delete")
    @RequiresPermissions(value = "商品管理")
    @ResponseBody
    public ServiceVO delete(Integer goodsId){
        return goodsService.delete(goodsId);
    }

    @RequestMapping("/getNoInventoryQuantity")
    @RequiresPermissions(value = "期初库存")
    public Map<String,Object> getNoInventoryQuantity(Integer page, Integer rows,String nameOrCode){
        return goodsService.getNoInventoryQuantity(page,rows,nameOrCode);
    }

    @RequestMapping("/getHasInventoryQuantity")
    @RequiresPermissions(value = "期初库存" )
    public Map<String,Object> getHasInventoryQuantity(Integer page, Integer rows,String nameOrCode){
        return goodsService.getHasInventoryQuantity(page,rows,nameOrCode);
    }

    @RequestMapping("/saveStock")
    @RequiresPermissions(value = "期初库存")
    public ServiceVO saveStock(Integer goodsId,Integer inventoryQuantity,double purchasingPrice){
        return goodsService.saveStock(goodsId,inventoryQuantity,purchasingPrice);
    }

    @RequestMapping("/deleteStock")
    @ResponseBody
    @RequiresPermissions(value = "期初库存")
    public ServiceVO deleteStock(Integer goodsId){
        return goodsService.deleteStock(goodsId);
    }

    @RequestMapping("/listAlarm")
    @RequiresPermissions(value = "库存报警")
    public Map<String,Object> listAlarm (){
        return goodsService.listAlarm();
    }





}
